package org.jgroups.protocols;

import org.jgroups.Header;
import org.jgroups.util.Streamable;

import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * User: thsieh
 * Date: Mar 15, 2010
 * Time: 11:21:49 AM
 * To change this template use File | Settings | File Templates.
 */
public class StreamHeader extends Header implements Streamable {

    // filename to be strarming
    private String filename;


    /**
     * empty constructure
     */
    public StreamHeader() {
    }

    /**
     *
     * @param filename 
     */
    public StreamHeader(String filename) {
        this.filename = filename;
    }

    public String getFilename() {
        return filename;
    }

    @Override
    public int size() {
        return filename.getBytes().length ;
    }

    @Override
    public String toString() {
        return filename;
    }

    public void writeExternal(ObjectOutput out) throws IOException {
//        out.writeObject(filename);
        out.writeUTF( filename);
    }

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
//        filename = (String) in.readObject();
        filename = in.readUTF() ;
    }

    public void writeTo(DataOutputStream out) throws IOException {
        out.writeUTF( filename);
    }

    public void readFrom(DataInputStream in) throws IOException, IllegalAccessException, InstantiationException {
        filename = in.readUTF();
    }
}
